package com.cn.validator;

import java.util.List;

import com.cn.model.User;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.validate.Validator;

public class GetRegisterValidator extends Validator {


	@Override
	protected void validate(Controller c) {
		validateRequired("user.username", "message", "用户名不能为空！");
		validateRequired("user.password", "message", "密码不能为空！");
		validateRequired("confirmpwd", "message", "请确认密码！");
		validateRequired("user.email", "message", "邮箱不能为空！");
		String username = c.getPara("user.username");
		String password = c.getPara("user.password");
		String confirmpwd = c.getPara("confirmpwd");
//		System.out.println(password);
//		System.out.println(confirmpwd);
		User user = User.dao.findFirst("SELECT * FROM USER WHERE username=?",username);
//		System.out.println(listsuser);
		if(user!=null){
			addError("message", "该用户名已存在！");
		}
		if(!password.equals(confirmpwd)){
			addError("message", "输入密码不一致！");
		}
	}

	@Override
	protected void handleError(Controller c) {
		c.setAttr("caozuo", false);
		c.renderJson();
	}

}
